$fn=100;

// Ship dimensions
ship_length = 150;
ship_width = 40;
ship_height = 30;

// Mast dimensions
mast_height = 100;
mast_radius = 4;

// Jewelry hanger dimensions
hanger_count = 4;
hanger_length = 30;
hanger_radius = 3;

// Text settings
text_height = 2;
text_size = 10;

// Nest dimensions
nest_radius = 20;
nest_height = 10;
nest_wall_thickness = 2;
nest_branch_count = 8;
nest_branch_radius = 1;
nest_branch_length = 15;

// Ship hull
module ship_hull() {
    difference() {
        resize([ship_length, ship_width, ship_height])
        intersection() {
            sphere(r=1);
            translate([0, 0, -0.3])
            cube([2, 1, 0.6], center=true);
        }
        
        // Add your name to the bottom of the ship hull
        translate([0, 0, -ship_height/2 - text_height])
        linear_extrude(height = text_height)
            text("Edis", size=text_size, font="Arial", halign="center", valign="center");
    }
}

// Deck
module deck() {
    translate([0, 0, ship_height/2]) {
        difference() {
            cube([ship_length*0.8, ship_width*0.8, ship_height/10], center=true);
            translate([ship_length*0.3, 0, 0])
            cube([ship_length*0.2, ship_width*0.6, ship_height/5], center=true);
        }
    }
}

// Mast with jewelry hanger and nest
module mast() {
    cylinder(h=mast_height, r=mast_radius);
    for (i=[1:hanger_count]) {
        rotate([0, 0, i*360/hanger_count])
        translate([0, mast_radius, i*mast_height/(hanger_count+1)])
        rotate([0, 90, 0])
        cylinder(h=hanger_length, r=hanger_radius);
    }
    translate([0, 0, mast_height])
    nest();
}

// Nest
module nest() {
    difference() {
        sphere(r=nest_radius);
        translate([0, 0, nest_height])
        cube([nest_radius*2, nest_radius*2, nest_height*2], center=true);
        sphere(r=nest_radius-nest_wall_thickness);
    }
    for (i=[1:nest_branch_count]) {
        rotate([0, 0, i*360/nest_branch_count])
        translate([0, nest_radius*0.8, 0])
        rotate([45, 0, 0])
        cylinder(h=nest_branch_length, r=nest_branch_radius);
    }
}

// Sails
module sails() {
    translate([0, 0, mast_height/2]) {
        rotate([0, 0, 30])
        cube([mast_height/2, 1, mast_height/2], center=true);
        rotate([0, 0, -30])
        cube([mast_height/2, 1, mast_height/2], center=true);
    }
}

// Rudder
module rudder() {
    translate([-ship_length*0.45, 0, -ship_height/2])
    rotate([0, 0, 30])
    resize([ship_length*0.3, ship_width*0.2, ship_height*0.8])
    sphere(r=1);
}

// Cannon ports
module cannon_ports() {
    for (i=[-1,1]) {
        translate([ship_length*0.2, i*ship_width*0.3, 0])
        rotate([0, 90, 0])
        cylinder(h=ship_length*0.1, r=ship_height*0.1);
    }
}

// Assemble the ship
module ship() {
    ship_hull();
    deck();
    translate([0, 0, ship_height/2])
    mast();
    sails();
    rudder();
    cannon_ports();
}

// Render the ship
ship();
